package com.elong.qadev.dao.impl;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.elong.qadev.dao.LogDaoI;
import com.elong.qadev.entity.Log_Case;
import com.elong.qadev.entity.Log_TaskInfo;
/**
 * 
* @ClassName: LogDaoImpl
* @Description: TODO(日志操作集合DAO)
* @author kangchen
* @date 2015年9月29日
*
 */
@Repository("logDao")
public class LogDaoImpl implements LogDaoI {
	Logger logger = Logger.getLogger(LogDaoImpl.class);

	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public boolean saveLog_h(Log_Case lh) {
		sessionFactory.getCurrentSession().save(lh);
		return true;
	}

	@Override
	public boolean saveLog_t(Log_TaskInfo lt) {
		sessionFactory.getCurrentSession().save(lt);
		return true;
	}

	@Override
	public ArrayList<Log_Case> getLogHttpCaseByBatchNumber(String batchNumber) {
		Criteria c = sessionFactory.getCurrentSession().createCriteria(
				Log_Case.class);
		c.add(Restrictions.eq("TaskBatchNumber", batchNumber));
		logger.debug("获取的结果是否为空："+c.list().isEmpty());
		if(c.list().isEmpty()){
			return null;
		}
		@SuppressWarnings("unchecked")
		ArrayList<Log_Case> h = (ArrayList<Log_Case>) c.list();
		return h;
	}

	@Override
	public Log_TaskInfo getLogTaskInfoByBatchNumber(String lastBatchNumber) {
		Criteria c = sessionFactory.getCurrentSession().createCriteria(
				Log_TaskInfo.class);
		c.add(Restrictions.eq("lastBatchNumber", lastBatchNumber));
		logger.debug("获取的结果是否为空："+c.list().isEmpty());
		if(c.list().isEmpty()){
			return null;
		}
		return (Log_TaskInfo) c.list().get(0);
	}

}
